/**
 * creation: 9-mrt-2006
 */
package org.jfonia.staffnotation;


/**
 * Immutable class representing a regular clef signature, i.e. a number of sharps or flats.
 * 
 * TODO: allow exotic signatures 
 * 
 * @author wijnand.schepens@gmail.com
 * 
 */
public class BasicKeySignature 
{

	private static final int[] sharps = {3, 0, 4, 1, 5, 2, 6}; //F, C, G, D, A, E, B
	private static final int[] flats  = {6, 2, 5, 1, 4, 0, 3}; //B, E, A, D, G, C, F

        private final int type; //Number of sharps (+) or flats (-)
	private final int[] mods;

	/**
	 * Constructs a new BasicKeySignature object.
	 * @param type number of sharps (+) or flats (-)
	 */
        public BasicKeySignature(int type)
        {
                this.type = type;

		mods = new int[7];
		for (int i=0; i<7; i++)
			mods[i] = 0;
		if (type > 0) //Sharps
		{
			for (int i=0; i<type; i++)
				mods[sharps[i]] = 1;
		}
		else if (type < 0) //Flats
		{
                        for (int i=0; i<-type; i++)
				mods[flats[i]] = -1;
		}

        }

	public int getType()
	{
		return type;
	}

	public int getModifierCount()
	{
		return Math.abs(type);
	}

	/**
	 * Returns the modifier of a given reduced rank.
	 * @param rr reduced rank or diatonic pitch class (0=C, 1=D, ..., 5=B)
	 * @return 0=natural, 1=sharp, -1=flat ...
	 */
	public int getModifier(int rr)
	{
		return mods[rr];
	}
}
